package com.application;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.application.base.BaseActivity;
import com.application.bean.Student;
import com.application.databinding.ActivitySqliteInsertBinding;
import com.application.util.ARouterConstants;
import com.application.viewmodel.SQLiteInsertViewModel;

@Route(path = ARouterConstants.ACTIVITY_URL_SQLITE_INSERT)
public class SQLiteInsertActivity extends BaseActivity<ActivitySqliteInsertBinding, SQLiteInsertViewModel> {
    @Override
    protected int initLayoutId() {
        return R.layout.activity_sqlite_insert;
    }

    @Override
    protected int initVariableId() {
        return BR.sqliteInsertViewModel;
    }

    @Override
    protected void initData() {
        super.initData();
        binding.setActivity(this);
        observeViewModelEvents();
    }

    private void observeViewModelEvents() {
        viewModel.clearInput.observe(this,shouldClear->{
            if (shouldClear!=null&& shouldClear){
                clearInputFields();
                viewModel.clearInput.setValue(false);
            }
        });
    }

    private void clearInputFields() {
        viewModel.nameLiveData.setValue("");
        viewModel.numberLiveData.setValue("");
        viewModel.scoreLiveData.setValue("");
        viewModel.genderLiveData.setValue("");
        binding.rgGender.clearCheck();
    }
    public void onInsertClick(){
        viewModel.handleInsert();
    }
}